<template>
  <div>
    <h2>添加员工</h2>
    用户名<input type="text" v-model="username">
    密码<input type="password" v-model="password">
    部门分类<select v-model="dept">
      <option v-for="i in depts" :key="i.id" :value="i.id">{{i.name}}</option>
    </select>
    <button @click="sub">添加</button>
  </div>
</template>

<script>
export default {
  data(){
    return{
      username:'',
      password:'',
      dept:0,
      depts:[]
    }
  },
  mounted(){
    this.axios({
      url:'http://127.0.0.1:8000/app01/dept/',
      method:'get'
    }).then(res=>{
      //
      this.depts=res.data;
    })
  },
  methods:{
    sub:function(){
      let data={
        username:this.username,
        password:this.password,
        dept:this.dept
      }
      this.axios({
        url:"http://127.0.0.1:8000/app01/user/",
        method:'post',
        data:data
      }).then(res=>{
        alert('添加成功')
      },error=>{
        alert(error.response.data);
      }
      )
    }
  }
}
</script>

<style>

</style>
